<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/10
 * Time: 9:23
 */
namespace app\admin\model;
use think\Model;
use think\Db;

class Appraise extends Model
{
    // 确定链接表名
    protected $name = 'appraise';

    public function getAppraiseList($where, $offset, $limit)
    {
        //查询所有的
        $res = $this->alias('a')
            ->field('a.*,u.nickname')
            ->join('user u','a.user_id=u.uid','left')
            ->where($where)->limit($offset, $limit)->order('a.app_id','desc')->select();
        foreach ($res as $k => $v) {
            //酒店
            if ($v['type'] == 1) {
                $hotel = Db::name('hotel')->field('hotel_name')->where('hotel_id', $v['item_id'])->find();
                if ($hotel !== false) {
                    $res[$k]['name'] = $hotel['hotel_name'];
                }
            }
            //景点
            if ($v['type'] == 2) {
                $tours = Db::name('tours')->field('tour_name')->where('tour_id', $v['item_id'])->find();
                if (!empty($tours)) {
                    $res[$k]['name'] = $tours['tour_name'];
                }
            }

            //旅行社
            if ($v['type'] == 3) {
                $item = Db::name('team')->field('team_name')->where('team_id', $v['item_id'])->find();
                if (!empty($item)) {
                    $res[$k]['name'] = $item['team_name'];
                }
            }

            //导游
            if ($v['type'] == 4) {
                $guide = Db::name('guide')->field('name')->where('guide_id', $v['item_id'])->find();
                if (!empty($guide)) {
                    $res[$k]['name'] = $guide['name'];
                }
            }

            //处理时间
            $res[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
        }

        return $res;
    }
    //总数
    public function getAppraiseCount($where)
    {
       return   $this->alias('a')
           ->field('a.*,u.nickname')
           ->join('user u','a.user_id=u.uid','left')->where($where)->count();
    }

    //删除
    public function appraiseDel($where)
    {
        return $this->where($where)->setField('is_display',1);
    }

    /**
     * [getAppInfo 获取评价详情]
     * @Author   kendy
     * @DateTime 2020-01-08T11:17:30+0800
     * @return   [type]                   [description]
     */
    public function getAppInfo($where){
        $result = $this
        ->field("app.app_id,u.nickname,app.images,app.create_time,app.is_display,app.eval_status,app.images,app.content,star")
        ->alias('app')
        ->join('user u','app.user_id=u.uid','left')
        ->where($where)
        ->find(); 
        if(!empty($result)){
        return $result;
        }
        return false;
   
    }



}